package com.fpj.sat.vehicle_administrator.view.dialog;
 
import java.io.InputStream;
import java.util.Map;

import javax.swing.JDialog;

import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JRViewer;

import com.fpj.sat.vehicle_administrator.util.Reporte;
import com.fpj.sat.vehicle_administrator.util.Util;

public class PdfDialog extends JDialog {
 
	private static final long serialVersionUID = -8695358650712987967L;
	private Map<String, Object> parameters;
    private InputStream reportStream;
  
    public PdfDialog(DetalleRegistroDialog detalleRegistroDialog, Map<String, Object> parameters) {
    	super(detalleRegistroDialog);
        this.parameters = parameters;
        inicializaDialog();
    }
    
    private void inicializaDialog() {
		//setLayout(null);
		setBounds(Util.getAnchoPantalla(getToolkit().getScreenSize(), 0.1), 0, Util.getAnchoPantalla(getToolkit().getScreenSize(), 0.8), Util.getAltoPantalla(getToolkit().getScreenSize(), 1));
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setTitle("Visor de Documentos");
	}
 
    public void setReportStream(InputStream reportStream) {
        this.reportStream = reportStream;
    }
 
    public void callReport() {
        JasperPrint jasperPrint = Reporte.generateReport(reportStream, parameters);
        JRViewer viewer = new JRViewer(jasperPrint);
        add(viewer);
        this.setVisible(true);
    }
 
    public void callConnectionLessReport() {
        JasperPrint jasperPrint = Reporte.generateEmptyDataSourceReport(reportStream, parameters);
        
        JRViewer viewer = new JRViewer(jasperPrint);
        add(viewer);
        this.setVisible(true);
    }
 
    public void closeReport() {
        //jasperViewer.setVisible(false);
    }
    
}